package com.cw.utils;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import com.alibaba.fastjson.JSONObject;
import com.cw.entity.MailInfo;
import lombok.extern.slf4j.Slf4j;

/**
 * @author Nice_BernardShaw
 * @date 2022/9/5 23:52
 */
@Slf4j
public class MailUtils {
    public static void sendMail2QQ(MailInfo mailInfo){
        try {
            log.info("=======进入QQ邮件发送方法=======");
            MailAccount account = new MailAccount();
            account.setHost("smtp.qq.com");
            account.setPort(587);
            account.setAuth(true);
//            设置发件人
            account.setFrom("2715858942@qq.com");
//            设置用户名
            account.setUser("2715858942@qq.com");
            //邮箱设置获取到的授权码
            account.setPass("qghobnpxhmqadgbg");
            MailUtil.send(account, CollUtil.newArrayList(mailInfo.getMails()),
                    mailInfo.getTitle(), mailInfo.getMessage(), true);
            log.info("=======QQ邮件发送成功=======,"+ JSONObject.toJSONString(mailInfo));
        } catch (Exception e) {
            log.error("=======QQ邮件发送失败=======,"+e.getMessage(),e);
        }

    }

}
